package jsyf.oa.dao.system;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.FastJsonConvert;
import jsyf.oa.entity.system.TipEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Maqiuqiu on 2018/4/24.
 */
@Repository
public class TipDao extends BaseDao {

    public TipDao() {

        this.iBaseEntity = new TipEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, TipEntity.class);
    }

    public List<JSONObject> getTipByType(String jsonData){
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String tipType = jsonParams.getString("tipType");
        StringBuffer condition = new StringBuffer();
        List<Object> sqlArgs = new ArrayList<Object>();
        if (!StringUtils.isBlank(tipType)) {
            condition.append(" AND TIP_TYPE = ? ");
            sqlArgs.add(tipType);
        }
        List<JSONObject> records = getJSONListByCondition(condition.toString(), sqlArgs.toArray());


        return records;
    }
}
